import { useRouter } from '@tarojs/taro';
import './index.scss';
import { historyInfo } from '../../configProvider/backendInterface';
import { View } from '@tarojs/components';
import { useEffect, useState } from 'react';
import Taro from '@tarojs/taro';
import dayjs from '../../components/TUIKit/utils/dayjs';
import { IP_NAME } from '../../configProvider/namespace';
const HistoryDetails = () => {
  const [data, setData] = useState<historyInfo>();
  const router = useRouter();
  const { index } = router.params;
  useEffect(() => {
    Taro.request({
      url: `${IP_NAME}/conversation/get_group_msg?counselor_name=瓜皮&user_name=林忆宁&page=1&size=10&order=id asc`, //仅为示例，并非真实的接口地址
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)
        console.log('message data', res.data.data.items[index!].message)
        setData(res.data.data.items[index!]);
      }
    })
  }, [])
  const messageCard = (from: string, text: string, time: string) => {
    return <View className='message-container'>
      <View className='message-time'>{dayjs(time).format('YYYY/MM/DD hh:mm:ss')}</View>
      <View className='message-content'>
        <View className='message-from'>{from}:</View>
        <View className='message-text'>{text}</View>
      </View>
    </View>
  }
  return <View>
    <View className='comment-container'>
      <View className='comment-title'>我的评价</View>
      <View className='comment-counselor'>咨询师：{data?.counselor}</View>
      <View className='comment-score'>评分：{data?.evaluate}分</View>
      <View className='comment-text'>评价：{data?.conversationType}</View>
    </View>
    {data && data.message.rspMsgList.map((value) => {
      // return value.from_Account && messageCard(value.from_Account, value.msgBody[0].MsgContent.Text, value.MsgTimeStamp)
      return <View>
        {value.fromAccount && messageCard(value.fromAccount, value.msgBody[0].msgContent.text, value.msgTimeStamp)}
      </View>
    })}
  </View>
}
export default HistoryDetails;
